//
//  KFDChooseTeacherViewCell.m
//  KFD
//
//  Created by JIRENTIANXIANG on 7/12/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDChooseTeacherViewCell.h"
#import "KFDTeacher.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "KFDTeacherIntroViewComposer.h"
#import "ui_config.h"
#import "NSDate+format.h"

@interface KFDChooseTeacherViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *avatar;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIView *levelView;
@property (weak, nonatomic) IBOutlet UIImageView *tick;
@property (weak, nonatomic) IBOutlet UILabel *chooseLabel;

@end

@implementation KFDChooseTeacherViewCell

- (void)awakeFromNib {
    // Initialization code
    self.avatar.layer.cornerRadius=self.avatar.bounds.size.width/2;
    self.avatar.layer.masksToBounds=YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setTeacher:(KFDTeacher *)teacher
{
    _teacher=teacher;
    self.nameLabel.text=[NSString stringWithFormat:@"%@老师",teacher.realname];
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:teacher.face] placeholderImage:[UIImage imageNamed:@"avatar"]];
    for (int i=0; i<teacher.level; i++) {
        UIImageView* star=[[UIImageView alloc] initWithFrame:CGRectMake(i*12, 0, 12, 12)];
        star.image=[UIImage imageNamed:@"face-ico"];
        [self.levelView addSubview:star];
    }
    KFDTeacherIntroViewComposer* composer=[[KFDTeacherIntroViewComposer alloc] init];
    composer.teacher=teacher;
    CGFloat height=[composer layout];
    [self.contentView addSubview:composer.view];
    UIView* separator=[[UIView alloc] initWithFrame:CGRectMake(0, 47+height, SCREEN_WIDTH, 20)];
    separator.backgroundColor=KFD_BG_COLOR;
    [self.contentView addSubview:separator];
    self.tick.hidden=teacher.ischoose?NO:YES;
    self.chooseLabel.hidden=teacher.ischoose?NO:YES;
    if (teacher.ischoose) {
        self.chooseLabel.text=[NSString stringWithFormat:@"%@选择",teacher.choose_time.year_month_day];
    }
}

@end
